package cmdnumsortapp.asereda.com;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created with IntelliJ IDEA.
 * User: Sereda Aleksandr <asereda@outlook.com>
 * Date: 21.10.13
 * <p/>
 * Input data: input integer numbers from command line.
 * Output data: output sorted integer numbers to stdout.
 */

public class Application {

    final static int FIRST_ELEMENT = 0;
    final static String ARGS_REQUERED = "Please provide one or more integers as command line arguments.";
    final static String ARGS_INT_ONLY = "Specify integer arguments only.";
    final static String MSG_SORTED_OUPUT_ONE = "Sorted value:";
    final static String MSG_SORTED_OUPUT_MANY = "Sorted values:";

    public static void main(String... args) {
        if (args.length == 0) {
            System.out.println(ARGS_REQUERED);
        } else {
            ArrayList<Integer> list = new ArrayList<Integer>();
            for (String element : args) {

                try {
                    list.add(Integer.valueOf(element));
                } catch (NumberFormatException ex) {
                    System.out.println(ARGS_INT_ONLY);
                    return;
                }
            }

            if (args.length == 1) {
                System.out.println(MSG_SORTED_OUPUT_ONE + "\n " + args[FIRST_ELEMENT]);
            } else {
                System.out.println(MSG_SORTED_OUPUT_MANY + "\n");
                Collections.sort(list);
                Collections.reverse(list);
                for (Integer element : list) {
                    System.out.print(" " + element.toString());
                }
            }
        }
    }
}
